<script setup>
import {fileMenuStore} from "@/views/FileMenu/fileMenu";
import {homeStore} from "@/views/Home/home";
import * as selectService from "@/apis/selectService";
import {formatBytes} from "@/utils/ByteUtil";
import {ElMessage} from "element-plus";

const fileMenu = fileMenuStore()
const home = homeStore()

async function deleteFilePaths(){
  const str = getPaths()
  await fileMenu.deleteFilePaths(str)
  await home.selectFilePath(home.currentPath)
}

async function fileRename(){
  home.rightRow.rename = true
  home.rename = home.rightRow.fileName
}

async function download(){
  const str = getPaths()
  await home.downloadFiles(str)
}

function getPaths(){
  const list = home.tableData.filter(item => item.selected !== undefined && item.selected === true);
  let str = ""
  list.forEach(item => {
    str += item.filePath
    str += ","
  })
  if(str.endsWith(",")){
    str = str.substring(0,str.length -1)
  }
  return str
}

async function getFileSize(path){
  const res = await selectService.selectFileSize(path)
  const size = formatBytes(res.data.data)
  ElMessage({
    type:"success",
    message:`文件大小为 ${size}`
  })
}
</script>

<template>
  <div style="background-color:#efefef;">
    <div @click="download" style="margin-top: 10px;margin-left: 30px;margin-right: 30px;cursor: pointer">下载</div>
    <div @click="fileRename" style="margin-top: 10px;margin-left: 30px;margin-right: 30px;cursor: pointer">重命名</div>
    <div @click="deleteFilePaths" style="margin: 10px 30px">删除</div>
  </div>
</template>

<style scoped>

</style>